#pragma once
#include<iostream>
#include"Comm.hpp"



class Init
{
    public:
    Init()
    {
        int n=mkfifo(gpipefile.c_str(),gmode);
        if(n<0)
        {
            cout<<"mkfifo error"<<endl;
            return;
        }
        cout<<"mkfifo success "<<endl;
        //sleep(15);
    }
    ~Init()
    {
        int n=unlink(gpipefile.c_str());//关闭fifo
        if(n<0)
        {
            cout<<"unlink error"<<endl;
            return;
        }
        cout<<"unlink success "<<endl;
    }
};

Init init;




class Server
{
public:
    Server():_fd(gdefultfd)
    {
        
    }
    bool OpenfifoRead()
    {
        _fd=Openfifo(gForRead);
        if(_fd<0)return false;
        return true;
    }
    int Readfifo(string *out)
    {
        char buff[gsize];
        ssize_t rd=read(_fd,buff,sizeof(buff)-1);
        if(rd>0)
        {
            buff[rd]=0;
            *out=buff;
        }
        return rd;
    }
    void Closefifo()
    {
        ClosefifoHelper(_fd);
    }
    ~Server()
    {
       
    }
private:
    int _fd;
};


